package com.hopu.dy.service.impl;

import com.hopu.dy.mapper.GongNengMapper;
import com.hopu.dy.pojo.GongNeng;
import com.hopu.dy.service.IGongNengService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class GongNengServiceImpl implements IGongNengService {
    @Resource
    private GongNengMapper gongNengMapper;

    @Override
    public GongNeng getByShipinId(long shipinId) {
        return gongNengMapper.selectByShipinId(shipinId);
    }
    //点赞
    @Override
    public boolean updateLoveNumber(long shipinId) {
        GongNeng gongNeng = gongNengMapper.selectByShipinId(shipinId);
        if (gongNeng == null) {
            return false;
        }
        gongNeng.setLoveNumber(gongNeng.getLoveNumber() + 1);
        return gongNengMapper.updateLoveNumber(gongNeng) > 0;
    }
    //评论
    @Override
    public boolean updatePinglunNumber(long shipinId) {
        GongNeng gongNeng = gongNengMapper.selectByShipinId(shipinId);
        if (gongNeng == null) {
            return false;
        }
        gongNeng.setPinglunNumber(gongNeng.getPinglunNumber() + 1);
        return gongNengMapper.updatePinglunNumber(gongNeng) > 0;
    }
    //转发
    @Override
    public boolean updateZhuanfaNumber(long shipinId) {
        GongNeng gongNeng = gongNengMapper.selectByShipinId(shipinId);
        if (gongNeng == null) {
            return false;
        }
        gongNeng.setZhuanfaNumber(gongNeng.getZhuanfaNumber() + 1);
        return gongNengMapper.updateZhuanfaNumber(gongNeng) > 0;
    }
    //收藏
    @Override
    public boolean updateShoucangNumber(long shipinId) {
        GongNeng gongNeng = gongNengMapper.selectByShipinId(shipinId);
        if (gongNeng == null) {
            return false;
        }
        gongNeng.setShoucangNumber(gongNeng.getShoucangNumber() + 1);
        return gongNengMapper.updateShoucangNumber(gongNeng) > 0;
    }
}